<template>
  <a-modal title="任务优先级调整" v-model="innerVisible" @ok="onConfirm" :afterClose="afterClose">
    <a-form :form="form" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
      <a-form-item label="优先级">
        <a-select v-decorator="rule" placeholder="请选择..." >
          <a-select-option :key="1" :value="1">1级</a-select-option>
          <a-select-option :key="2" :value="2">2级</a-select-option>
          <a-select-option :key="3" :value="3">3级</a-select-option>
          <a-select-option :key="4" :value="4">4级</a-select-option>
          <a-select-option :key="5" :value="5">5级</a-select-option>
          <a-select-option :key="6" :value="6">6级</a-select-option>
          <a-select-option :key="7" :value="7">7级</a-select-option>
          <a-select-option :key="8" :value="8">8级</a-select-option>
          <a-select-option :key="9" :value="9">9级</a-select-option>
          <a-select-option :key="10" :value="10">10级</a-select-option>
        </a-select>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { WmsTaskUpdateLevel } from '@/api/modular/main/WmsTaskManage'
export default {
  name:'wmsTaskPriorityModal',
  emits:['update:visible','confirm'],
  props:{
    row:{
      type:Object,
      default:function(){
        return {}
      }
    },
    visible:{
      type:Boolean,
      default:false
    }
  },
  data(){
    return {
      title:'',
      labelText:'',
      innerVisible:false,
      form: this.$form.createForm(this, { name: 'choose-site-form' }),
      sites:[],
      rule:['Tasklevel',{rules:[
        { required: true, message: '请确认优先级' }
      ]}]
    }
  },
  watch:{
    visible(newVal,oldVal){
      this.changeInnerVisible()
    },
    innerVisible(newVal,oldVal){
      this.changeVisible()
    }
  },
  methods:{
    changeInnerVisible(){
      if (this.visible!==this.innerVisible){
        this.innerVisible = this.visible
        if (this.innerVisible) {
          this.$nextTick(()=>{
            this.opened()
          })
        }
      }
    },
    changeVisible(){
      if (this.innerVisible!==this.visible){
        this.$emit('update:visible',this.innerVisible)
      }
    },
    opened(){
      //this.getSites()
    },
    onConfirm(){
      this.form.validateFields((err, values) => {
        if (!err) {
          let params = {...values}
          params.Id = this.row.id;
          WmsTaskUpdateLevel(params).then(()=>{
            this.innerVisible = false;
            this.$message.success('操作成功')
            this.$emit('confirm')
          }).catch(()=>[
            
          ])
        } 
      });
    },
    afterClose(){
      try{
        this.form.resetFields()
      }catch(e){
        
      }
    }
  },
  created(){
    this.changeInnerVisible()
  }
}
</script>

<style>
</style>